/*     */ package com.zimbra.qa.unittest.prov.soap;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.SoapTransport;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.qa.unittest.TestUtil;
/*     */ import com.zimbra.qa.unittest.prov.ProvTest.Sequencer;
/*     */ import com.zimbra.soap.account.message.AuthRequest;
/*     */ import com.zimbra.soap.account.message.AutoCompleteGalRequest;
/*     */ import com.zimbra.soap.account.message.ChangePasswordRequest;
/*     */ import com.zimbra.soap.account.message.CreateIdentityRequest;
/*     */ import com.zimbra.soap.account.message.CreateSignatureRequest;
/*     */ import com.zimbra.soap.account.type.Identity;
/*     */ import com.zimbra.soap.account.type.Signature;
/*     */ import com.zimbra.soap.mail.message.CreateDataSourceRequest;
/*     */ import com.zimbra.soap.mail.message.CreateDataSourceResponse;
/*     */ import com.zimbra.soap.mail.message.CreateFolderRequest;
/*     */ import com.zimbra.soap.mail.message.CreateFolderResponse;
/*     */ import com.zimbra.soap.mail.message.DeleteDataSourceRequest;
/*     */ import com.zimbra.soap.mail.type.Folder;
/*     */ import com.zimbra.soap.mail.type.MailPop3DataSource;
/*     */ import com.zimbra.soap.mail.type.MdsConnectionType;
/*     */ import com.zimbra.soap.mail.type.NewFolderSpec;
/*     */ import com.zimbra.soap.mail.type.Pop3DataSourceNameOrId;
/*     */ import com.zimbra.soap.type.AccountBy;
/*     */ import com.zimbra.soap.type.AccountSelector;
/*     */ import org.junit.AfterClass;
/*     */ import org.junit.Assert;
/*     */ import org.junit.BeforeClass;
/*     */ import org.junit.Test;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestAccess
/*     */   extends SoapTest
/*     */ {
/*     */   private static final String PASSWORD = "test123";
/*     */   private static String ACCT_NAME;
/*     */   private static String ACCT_ID;
/*     */   private static SoapTransport ACCT;
/*     */   private static String OTHER_ACCT_NAME;
/*     */   private static String OTHER_ACCT_ID;
/*     */   private static SoapTransport OTHER_ACCT;
/*     */   private static SoapProvTestUtil provUtil;
/*     */   private static Provisioning prov;
/*     */   private static Domain domain;
/*  66 */   private static ProvTest.Sequencer seq = new ProvTest.Sequencer();
/*     */   
/*     */   @BeforeClass
/*     */   public static void init() throws Exception {
/*  70 */     provUtil = new SoapProvTestUtil();
/*  71 */     prov = provUtil.getProv();
/*  72 */     domain = provUtil.createDomain(baseDomainName());
/*     */     
/*  74 */     ACCT_NAME = TestUtil.getAddress("acct", domain.getName());
/*  75 */     Account acct = provUtil.createAccount(ACCT_NAME);
/*  76 */     ACCT_ID = acct.getId();
/*  77 */     ACCT = authUser(ACCT_NAME);
/*     */     
/*  79 */     OTHER_ACCT_NAME = TestUtil.getAddress("other-acct", domain.getName());
/*  80 */     Account otherAcct = provUtil.createAccount(OTHER_ACCT_NAME);
/*  81 */     OTHER_ACCT_ID = otherAcct.getId();
/*  82 */     OTHER_ACCT = authUser(OTHER_ACCT_NAME);
/*     */   }
/*     */   
/*     */   @AfterClass
/*     */   public static void cleanup() throws Exception {
/*  87 */     Cleanup.deleteAll(new String[] { baseDomainName() });
/*     */   }
/*     */   
/*     */   private void accessTest(Perm perm, Object jaxbObject) throws Exception {
/*  91 */     for (Role role : ) {
/*  92 */       accessTest(role, perm, jaxbObject);
/*     */     }
/*     */   }
/*     */   
/*     */   private void accessTest(Role role, Perm perm, Object jaxbObject) throws Exception
/*     */   {
/*  98 */     String expectedCode = perm.getByRole(role);
/*  99 */     String resultCode = null;
/*     */     try
/*     */     {
/* 102 */       switch (role) {
/*     */       case R_USER: 
/* 104 */         invokeJaxb(ACCT, jaxbObject);
/* 105 */         break;
/*     */       case R_USER_TARGET_SELF: 
/* 107 */         invokeJaxbOnTargetAccount(ACCT, jaxbObject, ACCT_ID);
/* 108 */         break;
/*     */       case R_USER_TARGET_OTEHRUSER: 
/* 110 */         invokeJaxbOnTargetAccount(ACCT, jaxbObject, OTHER_ACCT_ID);
/* 111 */         break;
/*     */       default: 
/* 113 */         Assert.fail();
/*     */       }
/* 115 */       resultCode = "OK";
/*     */     } catch (ServiceException e) {
/* 117 */       resultCode = e.getCode();
/*     */       
/* 119 */       if (!expectedCode.equals(resultCode)) {
/* 120 */         e.printStackTrace();
/*     */       }
/*     */     }
/*     */     
/* 124 */     Assert.assertEquals(expectedCode, resultCode);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void Auth()
/*     */     throws Exception
/*     */   {
/* 131 */     AccountSelector acct = new AccountSelector(AccountBy.name, OTHER_ACCT_NAME);
/*     */     
/* 133 */     AuthRequest req = new AuthRequest(acct, "test123");
/*     */     
/* 135 */     accessTest(Perm.PERM_AUTH_TOKEN_IGNORED, req);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void AutoCompleteGal() throws Exception {
/* 140 */     AutoCompleteGalRequest req = AutoCompleteGalRequest.createForName("zimbra");
/* 141 */     accessTest(Perm.PERM_SELF_ONLY, req);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void ChangePassword() throws Exception {
/* 146 */     AccountSelector acct = new AccountSelector(AccountBy.name, ACCT_NAME);
/*     */     
/* 148 */     ChangePasswordRequest req = new ChangePasswordRequest(acct, "test123", "test123");
/* 149 */     accessTest(Perm.PERM_AUTH_TOKEN_IGNORED, req);
/*     */     
/*     */ 
/*     */ 
/* 153 */     ACCT = authUser(ACCT_NAME);
/*     */   }
/*     */   
/*     */   private String createFolderAndReturnFolderId() throws Exception {
/* 157 */     String folderName = "/folder-" + seq.next();
/*     */     
/* 159 */     SoapTransport transport = authUser(ACCT_NAME);
/* 160 */     NewFolderSpec folterSpec = new NewFolderSpec(folderName);
/* 161 */     CreateFolderRequest req = new CreateFolderRequest(folterSpec);
/* 162 */     CreateFolderResponse resp = (CreateFolderResponse)invokeJaxb(transport, req);
/*     */     
/* 164 */     return resp.getFolder().getId();
/*     */   }
/*     */   
/*     */   private CreateDataSourceRequest buildCeateDataSourceRequest(String dateSourceName) throws Exception
/*     */   {
/* 169 */     MailPop3DataSource dataSource = new MailPop3DataSource();
/* 170 */     dataSource.setName(dateSourceName);
/* 171 */     dataSource.setEnabled(Boolean.TRUE);
/* 172 */     dataSource.setMdsConnectionType(MdsConnectionType.ssl);
/* 173 */     dataSource.setHost("pop3.google.com");
/* 174 */     dataSource.setPort(Integer.valueOf(8888));
/* 175 */     dataSource.setUsername("my-pop3-name");
/* 176 */     dataSource.setPassword("my-pop3-password");
/* 177 */     dataSource.setFolderId(createFolderAndReturnFolderId());
/*     */     
/* 179 */     CreateDataSourceRequest req = new CreateDataSourceRequest();
/* 180 */     req.setDataSource(dataSource);
/*     */     
/* 182 */     return req;
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void CreateDataSource() throws Exception {
/* 187 */     String dateSourceName = genDataSourceName(seq);
/*     */     
/* 189 */     CreateDataSourceRequest req = buildCeateDataSourceRequest(dateSourceName);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 204 */     accessTest(Perm.PERM_SELF_ONLY, req);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void CreateIdentity() throws Exception {
/* 209 */     String identityName = genIdentityName(seq);
/* 210 */     Identity identity = Identity.fromName(identityName);
/* 211 */     CreateIdentityRequest req = new CreateIdentityRequest(identity);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 217 */     accessTest(Perm.PERM_SELF_ONLY, req);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void CreateSignature() throws Exception {
/* 222 */     String signatureName = genSignatureName(seq);
/*     */     
/* 224 */     Signature sig = new Signature((String)null, signatureName, (String)null, (String)null);
/* 225 */     CreateSignatureRequest req = new CreateSignatureRequest(sig);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 232 */     accessTest(Perm.PERM_SELF_ONLY, req);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void DeleteDataSource() throws Exception {
/* 237 */     String dateSourceName = genDataSourceName(seq);
/*     */     
/*     */ 
/* 240 */     SoapTransport transport = authUser(ACCT_NAME);
/* 241 */     CreateDataSourceRequest createReq = buildCeateDataSourceRequest(dateSourceName);
/* 242 */     CreateDataSourceResponse createResp = (CreateDataSourceResponse)invokeJaxb(transport, createReq);
/* 243 */     Assert.assertNotNull("CreateDataSourceResponse", createResp);
/*     */     
/* 245 */     Pop3DataSourceNameOrId name = new Pop3DataSourceNameOrId();
/* 246 */     name.setName(dateSourceName);
/* 247 */     DeleteDataSourceRequest req = new DeleteDataSourceRequest();
/* 248 */     req.addDataSource(name);
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 258 */     accessTest(Perm.PERM_SELF_ONLY, req);
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private static class Perm
/*     */   {
/*     */     static final String OK = "OK";
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 415 */     static final Perm PERM_SELF_ONLY = new Perm("OK", "OK", "service.PERM_DENIED");
/* 416 */     static final Perm PERM_AUTH_TOKEN_IGNORED = new Perm("OK", "OK", "OK");
/*     */     
/* 418 */     String[] mPerms = new String[TestAccess.Role.values().length];
/*     */     
/*     */     Perm(String user, String userTargetSelf, String userTargetOtherUser) {
/* 421 */       this.mPerms[TestAccess.Role.R_USER.ordinal()] = user;
/* 422 */       this.mPerms[TestAccess.Role.R_USER_TARGET_SELF.ordinal()] = userTargetSelf;
/* 423 */       this.mPerms[TestAccess.Role.R_USER_TARGET_OTEHRUSER.ordinal()] = userTargetOtherUser;
/*     */     }
/*     */     
/*     */     String getByRole(TestAccess.Role role) {
/* 427 */       return this.mPerms[role.ordinal()];
/*     */     }
/*     */   }
/*     */   
/*     */   private static enum Role {
/* 432 */     R_USER, 
/* 433 */     R_USER_TARGET_SELF, 
/* 434 */     R_USER_TARGET_OTEHRUSER;
/*     */     
/*     */ 
/*     */ 
/*     */     private Role() {}
/*     */   }
/*     */   
/*     */ 
/*     */   public void testAccess()
/*     */     throws Exception
/*     */   {
/*     */     Role role;
/*     */     
/* 447 */     for (role : ) {}
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/prov/soap/TestAccess.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */